#include <stdio.h>
#include "properties.h"

//计算树的高度
int treeHeight(TreeNode* root){
    //递归到最底部的时候，初始化leftHight、rightHight为0。或者为空树的时候直接返回0
    if(root == NULL) return 0;

    int leftHight = treeHight(root->left);
    int rightHight = treeHight(root->right);

    //若leftHight > rightHight，返回leftHight ，否则返回rightHight，之后再加1
    return (leftHight > rightHight ? leftHight : rightHight) + 1;
    //区分于python，python中的语法可以表示为return max(leftHeight, rightHeight) + 1;
    //要自己推一遍！
}


//计算树的节点个数
int countNodes(TreeNode* root){
    if(root == NULL) return 0;

    return countNodes(root->left) + countNodes(root->right) + 1;
}


// 计算叶子节点数
int countLeaves(TreeNode* root) {
    if (root == NULL) return 0;
    
    if (root->left == NULL && root->right == NULL) return 1;
    
    return countLeaves(root->left) + countLeaves(root->right);
}